#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        if(nums.empty()) return 0;
        int n = nums.size();
        int length = 1;
        for(int i=1; i<n; ++i){
            if(nums[i]!=nums[length-1]){
                nums[length++] = nums[i];
            }
        }
        return length;
    }
};